/*
 *  Blazon: A user datagram protocol re-braodcasting daemon.
 *  config.h: Header file for config.c
 *
 *  Copyright 2012 Blazon development team
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.

 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_config_h
#define INCLUDED_config_h

#define CONF_FILENAME	"blazon.conf"

#define CONF_NAME_LEN	32
#define CONF_VALUE_LEN	220
#define CONF_LINE_LEN	255

#define CONF_TYPE_INT	1
#define CONF_TYPE_BOOL	2
#define CONF_TYPE_STR	3
#define CONF_TYPE_SUBNET	4
#define CONF_TYPE_GAME	5


struct config_file
{
	char *listen;
	char *pidfile;
	char *statsfile;
	char *logfile;
	int loglevel;
	int stats_freq;
	int hashlog_freq;
	int hashclean_freq;
	int hashnode_life;

	dlink_list game_list;
	dlink_list subnet_list;

	struct subnet_info *subnets;	/* array of subnet structs */
	uint16_t subnets_size;			/* count of subnets */
};

struct table_entry
{
	const char *name;
	int8_t type;		/* Config entry type */
	size_t cfg_off;		/* Offset (in bytes) of location in config_file */
};


struct game_info
{
	char *name;				/* Name of the game */
	uint16_t port;			/* Port used by game */
	uint16_t *lens;			/* acceptable payload lengths */
	uint8_t lens_size;		/* acceptable payload lengths */
	fdext_t *fd_ptr;		/* ptr to extended fd struct */
	uint32_t sentcount;		/* incremented once per processed broadcast */
	uint32_t throtcount;	/* incremented once per throttled packet */
};

struct subnet_info
{
	char subnet[19];		/* Subnet the pkt came from */
	char broadcast[16];		/* Broadcast addr to send to */
};

extern void config_init(void);
extern bool load_config(struct config_file **);
extern void destroy_config(struct config_file *);
extern void write_config_file(struct config_file *);

#endif
